%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  本脚本会简单使用th1 和th2两个阈值来初筛背景点。脚本分完类后会在最开始的points的class维度上打上对应类别，0为地面点，1为塔线点
%  本脚本会在grid_map中新增两个属性。其中
%  class表示格点中是否有塔线点，1为有，0为无
%  fgnum表示格点中塔线点的数量
%-input args:
%     grid_map:  记录格点信息的结构体
% -output args:
%     无
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for i = 1:size(grid_map,1)
    for j = 1:size(grid_map,2)
        disp(['processing: (',num2str(i),',',num2str(j),')']);
        if grid_map(i,j).point_num>1
            if grid_map(i,j).dh>th1
                [m,ind] = max(grid_map(i,j).dp);
                p = sortrows(grid_map(i,j).points,3);
                if m>th2
                    grid_map(i,j).points = p;
                    grid_map(i,j).points(ind+1:size(p,1),5)=1;
                    grid_map(i,j).class = 1;
                    grid_map(i,j).fgnum = length([ind+1:size(p,1)]);
                    for k =ind+1:size(p,1)
                        points(p(k,4),5) =1;
                        
                    end
                else
                    grid_map(i,j).class = 0;
                    grid_map(i,j).fgnum = 0;
                end
            
            else
                grid_map(i,j).class = 0;
                grid_map(i,j).fgnum = 0;
            end
        else
            grid_map(i,j).class = 0;
            grid_map(i,j).fgnum = 0;
        end
    end
end






